import java.util.Random;
import java.util.Scanner;





public class Test3 {
    public static void main1(String[] args) {
        //Scanner + 自取名 = new Scanner（System.in)   标准输入写in 读取文本写text
        Scanner scan = new Scanner(System.in);

        System.out.println("请输入你的姓名:");
        String name = scan.nextLine();//注意:nextLine会把回车符读进去，要是上面还有输入就再加一行scan.nextLine() 不能只写next 如果输入的字符有空格就会停止报错
        System.out.println(name);

        System.out.println("请输入你的年龄:");
        int age = scan.nextInt();//想输入字符就是nextChar() 浮点型就是nextDouble()
        System.out.println(age);

        System.out.println("请输入你的体重：");
        int weight = scan.nextInt();
        System.out.println(weight);
    }





    //使⽤Scanner循环读取N个数字，并求取其平均值
    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);

        int sum = 0;
        int num = 0;

        while (sc.hasNextInt()) {
            int tmp = sc.nextInt();
            sum += tmp;
            num++;
        }

        System.out.println("sum = " + sum);
        System.out.println("avg = " + sum / num);
        sc.close();

    }





    public static void main3(String[] args) {
        //生成随机数的代码
        Random random = new Random();
        int num = random.nextInt(100)+10;//随机生成数范围为 [10,110)
        System.out.println(num);
    }




    public static void main(String[] args) {

        //猜数字游戏
        int count = 3;//可输入次数为3
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        int randomNum = random.nextInt(100);//生成[0,100)的随机数

        while (count != 0){
            System.out.println("请输入您猜的数字");
            int num = scanner.nextInt();
            if (randomNum < num){
                System.out.println("猜大了");
            } else if (randomNum == num) {
                System.out.println("恭喜你猜对了!");
                break;
            }else{
                System.out.println("猜小了");
            }
            count--;
            System.out.println("你还有" + count + "次机会");
        }

        System.out.println("正确答案是：" + randomNum);
    }


}